<template>
  <div class="login">
    <div class="box">
      <h2 align="center">积云会员管理系统</h2>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        class="demo-ruleForm"
      >
        <el-form-item
          label="用户名"
          prop="username"
          style="width: 400px; margin-top: 40px"
        >
          <el-input placeholder="请输入用户名" v-model="ruleForm.username"></el-input>
        </el-form-item>
        <el-form-item
          label="密码"
          prop="password"
          style="width: 400px; margin-top: 40px"
        >
          <el-input placeholder="请输入密码" v-model="ruleForm.password" show-password></el-input>
        </el-form-item>
      </el-form>
      <p class="login-btn" align="center" style="margin-top:40px">
        <el-button class="btn" type="primary" @click="loginClick">登录</el-button>
      </p>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 8, message: "长度在 3 到 8 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 8, message: "长度在 3 到 8 个字符", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
      
  },
  methods: {
      async loginClick() {
          let res = await request.post('/user/login',this.ruleForm)
        //   console.log(res);
          if(res.data.flag == true){
              localStorage.token = res.data.data.token
              this.$router.push('/home')
              this.$message.success(res.data.message)
          }else{
              this.$message.error(res.data.message)
          }
      }
  },
};
</script>

<style scoped lang="scss">
.login {
  width: 100%;
  height: 100%;
  background-color: cadetblue;
  display: flex;
  align-items: center;
  justify-content: center;
}
.box {
  width: 800px;
  height: 380px;
  background-color: aliceblue;
  padding-top: 30px;
}
.demo-ruleForm {
  padding: 0 170px;
}
</style>
